Add status filtering to the runs endpoint#481
Open
Aryan95614 wants to merge 2 commits into
Open
Conversation
GET /flows/{flow_id}/runs now takes a status query parameter
(running/completed/failed), repeatable to match more than one.
Status is derived from the run's end-attempt metadata, reusing the
same definition the UI backend serves so the two agree. It is applied
as a WHERE predicate over the existing query path, so it composes with
limit/offset rather than replacing it; the join is only enabled when a
status filter is present, leaving the plain listing untouched. Unknown
status values are rejected with a 400.
b531509 to
dc6bf42
Compare
Cover the first branch of the run-status CASE: a run whose 'end' step failed (attempt_ok=false) but has a newer 'attempt' record is being retried and must read as running, not failed. The branch turns on a strict ts_epoch comparison between the two metadata rows, so the test stamps their timestamps explicitly via update_row rather than relying on insert order. Completes coverage of all five status branches.
saikonen
reviewed
Jun 23, 2026
saikonen
left a comment
Collaborator
There was a problem hiding this comment.
looks good so far. Let's wait for the run pagination PR to go in so this can be modified to support cursor based pagination as well.
| # joins below pull the 'end' step's attempt metadata that the status depends on. | ||
| # Only used when joins are enabled (i.e. when filtering by status), so the plain | ||
| # get_all_runs path stays a simple, join-free query. | ||
| joins = [ |
Collaborator
There was a problem hiding this comment.
battle-tested query logic from the ui_backend side, and this is gated behind the status query param, so from a performance perspective it should be fine to add to the metadata-service as well.
The only concern is with status=failed&status=running which is in the case of relying on heartbeats, not entirely deterministic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
statusquery parameter toGET /flows/{flow_id}/runsso a run listing can be filtered to running / completed / failed without pulling every row and filtering client-side. The parameter is repeatable (?status=running&status=failed) to match more than one status; unknown values return 400.Status is derived from the run's end-attempt metadata using the same definition
ui_backend_servicealready serves, so the two agree. It is applied as aWHEREpredicate over the existing query path, and the joins are only enabled when a status filter is present, so the plain listing is unchanged. Because the predicate lives in theWHERE, it composes withlimit/offsetinstead of replacing them — a filtered page is the matching rows taken after filtering.Tested against real Postgres: status classification (completed wins over a live heartbeat, explicit
attempt_ok=false, stale heartbeat, running), repeated-param OR, the 400 path, and that the filter composes with a limited page.Known test-coverage gap: the failed-then-retrying -> running branch isn't covered yet (needs deterministic metadata timestamps in the test helper).